<template>
  <div class="m-2 mr-0 overflow-hidden bg-white h-full]">
    <BasicTree
title="部门列表" treeWrapperClassName="h-[calc(100%-40px)] overflow-auto" :clickRowToExpand="false"
      :treeData="treeData" :fieldNames="{ key: 'id', title: 'name' }" @select="handleSelect" />
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { BasicTree, TreeItem } from '@/components/Tree'
import { getOrganizationTree } from '@/api/sys/dept';

defineOptions({ name: 'DeptTree' })

const emit = defineEmits(['select'])

const treeData = ref<TreeItem[]>([])

async function fetch() {
  const res = await getOrganizationTree()
  // console.log(res)
  treeData.value = (await getOrganizationTree()) as unknown as TreeItem[]
}

function handleSelect(keys) {
  emit('select', keys[0])
}

onMounted(() => {
  fetch()
})
</script>
